//package com.example.demo;
//
//import org.apache.commons.io.IOUtils;
//import org.apache.hadoop.conf.Configuration;
//import org.apache.hadoop.fs.*;
//import org.junit.Test;
//
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.net.URI;
//import java.net.URISyntaxException;
//
//public class Hadoop_test {
//    @Test
//    public void list_File() throws Exception {
//
//        FileSystem fileSystem = FileSystem.get(new URI("hdfs://node02:8020"), new Configuration());
//        System.out.println(fileSystem.toString());
//        FileStatus[] fileStatuses = fileSystem.listStatus(new Path("/"));
//        for (FileStatus fileStatus : fileStatuses) {
//            if (fileStatus.isDirectory()) {
//                Path p = fileStatus.getPath();
//                listAllFiles(fileSystem, p);
//            }else {
//                Path path1 = fileStatus.getPath();
//                System.out.println("路径为" + path1);
//            }
//        }
//        fileSystem.close();
//    }
//    public void listAllFiles(FileSystem fileSystem, Path path) throws Exception {
//        FileStatus[] fileStatuses = fileSystem.listStatus(path);
//        for (FileStatus fileStatus : fileStatuses) {
//            if (fileStatus.isDirectory()) {
//                listAllFiles(fileSystem, fileStatus.getPath());
//            } else {
//                Path path1 = fileStatus.getPath();
//                System.out.println("路径为" + path1);
//            }
//        }
//    }
//    @Test
//    public void Api_listFile() throws URISyntaxException, IOException {
//        FileSystem fileSystem =FileSystem.get(new URI("hdfs://node02:8020"),new Configuration());
//        RemoteIterator<LocatedFileStatus> locatedFileStatusRemoteIterator = fileSystem.listFiles(new Path("/"),true);
//        while (locatedFileStatusRemoteIterator.hasNext()){
//            LocatedFileStatus next = locatedFileStatusRemoteIterator.next();
//            System.out.println(next.getPath().toString());
//        }
//        fileSystem.close();
//    }
//    @Test
//    public void Api_Download() throws URISyntaxException, IOException {
//        FileSystem fileSystem = FileSystem.get(new URI("hdfs://node02:8020"),
//                new Configuration());
//        FSDataInputStream open = fileSystem.open(new Path("/test.txt"));
//        FileOutputStream fileOutputStream = new FileOutputStream("test.txt");
//        IOUtils.copy(open,fileOutputStream);
//        IOUtils.closeQuietly(open);
//        IOUtils.closeQuietly(fileOutputStream);
//        fileSystem.close();
//    }
//    @Test
//    public void Api_Upload() throws Exception{
//        String localPath="C:\\Users\\Administrator\\Desktop\\english_dialog.docx";
//        FileSystem fileSystem = FileSystem.get(new URI("hdfs://node02:8020"),
//                new Configuration());
//        fileSystem.copyFromLocalFile(new Path("file:///"+localPath), new Path("/english_dialog.docx"));
//    }
//}
